Skip to content

Reentry simulation: simulated parts no longer write into KSP's global lift and drag curves - #2799

Merged
sarbian merged 1 commit into
devfrom
fix/sim-global-curves
Nov 27, 2026
Merged

sarbian merged 1 commit into
devfrom
fix/sim-global-curves

Conversation

@sarbian

@sarbian sarbian commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

The bug (on dev)

SimulatedPart.CopyDragCubesList calls stock DragCubeList.SetPart, which points the cube list at the global PhysicsGlobals.BodyLiftCurve and PhysicsGlobals.SurfaceCurves (DragCubeList.cs SetPart). SimCurves.CopyTo then writes the simulation's curve copies into whatever the list holds: dest.BodyLiftCurve.liftCurve = _liftCurve, dest.SurfaceCurves.dragCurve* = …. So every landing prediction replaced KSP's global body lift and surface drag curves with one simulation's copies, and KSP's physics on the main thread and the next simulation on its thread pool thread evaluated the same AnimationCurves at once. Both read garbage, often 0.

The private containers SimulatedPart's pool Create made were replaced by SetPart straight away; SimulatedParachute's pool never made any.

Seen in flight (MechJeb2_UI Spike 185, Kerbal X pod, Land at KSC, heat shield first at 15 deg)

  • Half the predictions had no body lift: the predicted landing jumped between the pad and 20 km short of it, and course correction chased it (thousands of step switches).
  • Stock's own PhysicsGlobals.BodyLiftCurve.liftCurve evaluated on the main thread returned 0 at dot 0.3/0.6/0.9 on those samples (0.5735/0.9597/0.7804 otherwise), and the pod's real body lift reading stayed frozen at 0.642 kN for 26 km: stock's aerodynamics were very likely affected too, for any vessel, while predictions ran (indirect: measured on that reading only).

Fix

After SetPart, the cube list gets the part's own LiftingSurfaceCurve and SurfaceCurvesList back (fields of SimulatedPart, so the parachute subclass has them too). DragCurveCd / DragCurveCdPower / DragCurveMultiplier were never affected: CopyTo replaces those references, it doesn't write into them.

After the fix (3 flights): 0 of 275 samples with zero simulated lift, simulated lift = stock's within 0.88-1.01x at the same attitude, no prediction jumps.

PSG ascent isn't affected directly: its solver runs on MechJebLib's managed interpolants, and AutoAero (PSGAeroEstimate) and the atmosphere fit run on the main thread. AutoAero reads the global curves, so it could read garbage only while landing predictions ran at the same time, which this fix also ends.

…no longer KSP's global ones

DragCubeList.SetPart, called for each simulated part's cube list, points the list at the global
PhysicsGlobals.BodyLiftCurve and PhysicsGlobals.SurfaceCurves, and SimCurves.CopyTo then wrote the
simulation's curve copies into them. So every prediction replaced KSP's global body lift and surface drag
curves with one simulation's copies, and KSP's physics on the main thread and the next simulation on its
thread evaluated the same AnimationCurves at once. Both read garbage, often 0: in flight, half the
predictions of a lifting capsule had no body lift and landed 20 km short of the others, and stock's own
curve read 0 on the main thread.

The cube list now gets the part's own containers back after SetPart (the pool's Create gave it some, which
SetPart replaced at once; SimulatedParachute's pool never did).
@github-actions

Copy link
Copy Markdown
Contributor

✅ Build Artifact 🚀

MechJeb2-f41199a.zip (built from a491d77)

@sarbian
sarbian merged commit 6351757 into dev Nov 27, 2026
3 checks passed
@sarbian
sarbian deleted the fix/sim-global-curves branch November 27, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant